<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!--edge浏览器H5兼容设置-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!--360浏览器H5兼容设置-->
    <meta name="renderer" content="webkit" />
    <title>器材管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--导入核心文件-->
    <script src="../bootstrap3/js/holder.js"></script>
    <link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="../bootstrap3/jquery-1.9.1.min.js"></script>
    <script src="../bootstrap3/js/bootstrap.js"></script>
    <!-- 字体图标 -->
    <link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />

    <script src="../bootstrap3/js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>


    <link rel="stylesheet" type="text/css" href="../css/eqman.css"/>

</head>
<body>
<!--网页最上方的留白-->
<header>
    <!-- class.container 容器定位 的作用是进行居中布局 -->
    <div class="container">
        <!-- pull-right 向右对齐  -->
        <span class="pull-right"><small>Sports  Equipment</small> <b>Management</b>System</span>

    </div>
</header>

<!--网页 导航栏 在layout.css 文件中设置背景图片-->
<nav>
    <!-- class.container 容器定位 用于设置内容居中 -->
    <div class="container">
        <h1>
            <b>体育器材管理系统</b> <small>——Design by Z</small>
        </h1>

        <!--导航栏-->
        <div>
            <!-- class="nav navbar-nav" 定义导航条 -->
            <ul class="nav navbar-nav">
                <li><a href="home.html">首页</a></li>
                <li><a id="showlist">显示器材表</a></li>
                <li><a id="price">显示价目表</a></li>
                <li><a id="sup" >显示供应商表</a></li>

            </ul>
            <!-- class="nav navbar-nav" 定义导航条 向右侧浮动 -->
            <ul class="nav navbar-nav navbar-right">
                <!-- 导航条中的文字使用 class="navbar-text" 样式 -->
                <li><span class="navbar-text"></span></li>
                <li><a id="loginout"><span class="glyphicon glyphicon-off" aria-hidden="true"></span></a></li>
            </ul>
        </div>
        <!-- /导航栏 -->
    </div>
</nav>
<!--主体-->
<br>
<section>
    <div class="container">
        <div class="row" >



        </div>
    </div>


    <hr>

    <div class="container">
        <div class="row">
            <div class="col-md-2"></div>
            <div class="col-md-10" style="margin-left: 170px;" >
                <div id="table-container" style="width:800px;height:300px;">
                    <table class="table-hover">
                        <caption id="caption" style="padding-top: 4px;"></caption>
                        <thead>
                        <tr>
                            <th><div></div></th>
                            <th><div></div></th>
                            <th><div></div></th>
                            <th><div></div></th>


                        </tr>

                        </thead>
                        <tbody id="list">
                        <tr>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>



                        </tr>
                        <tr>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>



                        </tr> <tr>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>



                        </tr> <tr>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>



                        </tr> <tr>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>



                        </tr> <tr>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>



                        </tr> <tr>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>


                        </tr> <tr>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>


                        </tr>
                        <tr>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>



                        </tr>
                        <tr>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>
                            <td><div></div></td>



                        </tr>
                        </tbody>
                    </table>
                </div>

                <br>
            </div>
        </div>
        <div class="row">
            <div class="col-md-2"></div>
            <div class="col-md-10" style="margin-left: 170px;">
                <div  id="btn-container" style="align-content: center">
                    <input id="pageup" type="button" value="上一页">
                    <span id="page">1</span>
                    <input id="pagedpwn" type="button" value="下一页">
                </div>
            </div>

        </div>
    </div>



</section>

<!--页脚开始-->
<!--网页底部， class.well 用于设置背景效果-->
<footer class="well">
    <!-- class.container 的作用是进行居中布局 -->
    <div class="container">
        <b>Copyright © 2020 ？？.com All Rights Reserved
            <a href="#">啥也不是</a>
            版权所有
        </b> <span class="pull-right"> <b>Version</b> 1.1.0
      </span>
    </div>
</footer>
<!--页脚结束-->
<script type="text/javascript">
    /*员工表上传*/
    $("#btn-submit2").click(function() {
        var r=confirm("请确认文件命名是否符合规定要求")
        if (r){
            $.ajax({
                "url":"/users/uploademp",
                "data":new FormData($("#form-equ2")[0]),
                "contentType":false,
                "processData":false,
                "type":"post",
                "dataType":"json",
                "success":function(json) {
                    if (json.state == 4000) {
                        // 提示
                        alert("上传成功！");
                        window.location.href="/web/register.html"
                    }
                },
                "error":function(xhr) {
                    alert("\n\nHTTP响应码：" + xhr.status+"请联系管理员");
                    // location.href = "login.html";
                }
            });
        }else{
            $("#file2").val("")
        }

    });
    /*Excel上传按钮*/
    $("#btn-submit").click(function() {
        var r=confirm("请确认文件命名是否符合规定要求")
        if (r) {
            $.ajax({
                "url": "/equ/uploadequ",
                "data": new FormData($("#form-equ")[0]),
                "contentType": false,
                "processData": false,
                "type": "post",
                "dataType": "json",
                "success": function (json) {
                    if (json.state == 2000) {
                        // 提示
                        alert("上传成功！");
                        window.location.href = "equman.html"
                    }
                },
                "error": function (xhr) {
                    alert("\n\nHTTP响应码：" + xhr.status);
                    // location.href = "login.html";
                }
            });
        }else{
            $("#file1").val("")
        }
    });

    /*打开网页时，显示器材表*/
    $(document).ready(function () {
        if ($("#page").text()*1==1){
            $("#pageup").attr("disabled",true)
        }
        showlist(0)
        $.ajax({
            "url":"/users/loginnum",
            "type":"get",
            "dataType":"json",
            success:function (json) {
                console.log(json.data)
                if (json.data!=null){
                    $(".navbar-text").text("管理员："+json.data)
                    $("#showlist").removeAttr("disabled")
                    $("#price").removeAttr("disabled")
                    $("#sup").removeAttr("disabled")
                    $("#btn-submit").removeAttr("disabled")
                    $("#btn-submit2").removeAttr("disabled")
                }
            },
            "error":function () {

                $("#ul").prepend($('<li><a href="' +'http://localhost:8080/web/login.html'+ '">'+"登录"+'</a></li>'))
                $(".navbar-text").text(" ")
                        $("#showlist").attr("disabled",true)
                        $("#price").attr("disabled",true)
                        $("#sup").attr("disabled",true)
                        $("#btn-submit").attr("disabled",true)
                        $("#btn-submit2").attr("disabled",true)
            }
        })

    })

    $("#loginout").bind('click',function () {
        $.ajax({
            "url":"/users/logininfo",
            "type":"get",
            "dataType":"json",
            success:function (json) {
                if(json.state==2000){
                    window.location.href="login.html"
                }
            },
            "error":function () {

                $(".navbar-text").append($('<a href="' +'http://localhost:8080/web/login.html'+ '">'+"登录"+'</a>'))

            }
        })
    })

    /*显示器材表*/
    $("#showlist").bind('click',function (){
        pagenumber=0
        $("#page").text("1")
        if ($("#page").text()*1==1){
            $("#pageup").attr("disabled",true)
        }

        showlist(0)
    })

    /*显示价目表*/
    $("#price").bind('click',function (){
        pagenumber=0
        $("#page").text("1")
        if ($("#page").text()*1==1){
            $("#pageup").attr("disabled",true)
        }
        showprice(0);
    })

    /*显示供应商表*/
    $("#sup").bind('click',function (){
        pagenumber=0
        $("#page").text("1")
        if ($("#page").text()*1==1){
            $("#pageup").attr("disabled",true)
        }
        showsup(0);
    })

    var pagenumber=0;
    /*上一页*/
    $("#pageup").click(function () {
        console.log("当前页码"+$("#page").text())
        $("#page").text($("#page").text()*1-1)
        console.log("当前页码"+$("#page").text())
        console.log($("caption").text())
        if ($("caption").text() == "价格表"){
            showprice(($("#page").text()*1-1)*10)
        }
        if($("caption").text() == "器材表"){
            showlist(($("#page").text()*1-1)*10)
        }
        if($("caption").text() == "供应商表"){
            showsup(($("#page").text()*1-1)*10)
        }



    })
    /*下一页*/
    $("#pagedpwn").click(function () {

        $("#page").text($("#page").text()*1+1)
        console.log($("#page").text())
        console.log($("caption").text())
        if ($("caption").text() == "价格表"){
            showprice(($("#page").text()*1-1)*10)
        }
        if($("caption").text() == "器材表"){
            showlist(($("#page").text()*1-1)*10)
        }
        if($("caption").text() == "供应商表"){
            showsup(($("#page").text()*1-1)*10)
        }


    })




/*价格表*/
    function showprice(pagenumber){
        console.log("正在加载.........");
        for (let i=0;i<10;i++){
            $("#list").children().eq(i).children().children().eq(0).text("")
            $("#list").children().eq(i).children().children().eq(1).text("")
            $("#list").children().eq(i).children().children().eq(2).text("")
            $("#list").children().eq(i).children().children().eq(3).text("")
        }
        $.ajax({
            "url":"/equ/showprice?page="+pagenumber,
            "type":"get",
            "dataType":"json",
            "success":function(json) {
                if (json.data.length<10){
                    $("#pagedpwn").attr("disabled",true)
                }else{
                    $("#pagedpwn").attr("disabled",false)
                }
                if($("#page").text()*1>1){
                    $("#pageup").attr("disabled",false)
                }else if ($("#page").text()*1==1){
                    $("#pageup").attr("disabled",true)
                }
                $("caption").text("价格表")
                $("th:eq(0)").children().text("器材供应商")
                $("th:eq(1)").children().text("器材名称")
                $("th:eq(2)").children().text("器材价格")
                $("th:eq(3)").children().text("")


                console.log(json.data)
                var list=json.data
                for (let i=0;i<list.length;i++){
                    var sup=list[i]['sup']
                    var ename=list[i]['ename']
                    var price=list[i]['price']
                    console.log(sup)
                    console.log(ename)
                    console.log(price)
                    $("#list").children().eq(i).children().children().eq(0).text(sup)
                    $("#list").children().eq(i).children().children().eq(1).text(ename)
                    $("#list").children().eq(i).children().children().eq(2).text(price)

                }
            }
        });
    }
/*器材整理表*/
    function showlist(pagenumber){
        console.log("正在加载.........");
        for (let i=0;i<10;i++){
            $("#list").children().eq(i).children().children().eq(0).text("")
            $("#list").children().eq(i).children().children().eq(1).text("")
            $("#list").children().eq(i).children().children().eq(2).text("")
            $("#list").children().eq(i).children().children().eq(3).text("")


        }
        $.ajax({
            "url":"/equ/showlist?page="+pagenumber,
            "type":"get",
            "dataType":"json",
            "success":function(json) {
                if (json.data.length<10){
                    $("#pagedpwn").attr("disabled",true)
                }else{
                    $("#pagedpwn").attr("disabled",false)
                }
                if($("#page").text()*1>1){
                    $("#pageup").attr("disabled",false)
                }else if ($("#page").text()*1==1){
                    $("#pageup").attr("disabled",true)
                }
                $("caption").text("器材表")
                $("th:eq(0)").children().text("器材名称")
                $("th:eq(1)").children().text("器材数量")
                $("th:eq(2)").children().text(" ")
                $("th:eq(3)").children().text(" ")

                console.log(json.data)
                var list=json.data
                for (let i=0;i<list.length;i++){
                    var ename=list[i]['ename']
                    var enumber=list[i]['enumber']
                    console.log(ename)
                    console.log(enumber)
                    $("#list").children().eq(i).children().children().eq(0).text(ename)
                    $("#list").children().eq(i).children().children().eq(1).text(enumber)

                }
            }
        });
    }


    /*供应商表*/
    function showsup(pagenumber){
        console.log("正在加载.........");
        for (let i=0;i<10;i++){
            $("#list").children().eq(i).children().children().eq(0).text("")
            $("#list").children().eq(i).children().children().eq(1).text("")
            $("#list").children().eq(i).children().children().eq(2).text("")
            $("#list").children().eq(i).children().children().eq(3).text("")
        }
        $.ajax({
            "url":"/equ/showsup?page="+pagenumber,
            "type":"get",
            "dataType":"json",
            "success":function(json) {
                if (json.data.length<10){
                    $("#pagedpwn").attr("disabled",true)
                }else{
                    $("#pagedpwn").attr("disabled",false)
                }
                if($("#page").text()*1>1){
                    $("#pageup").attr("disabled",false)
                }else if ($("#page").text()*1==1){
                    $("#pageup").attr("disabled",true)
                }
                $("caption").text("供应商表")
                $("th:eq(0)").children().text("供应商")
                $("th:eq(1)").children().text("联系方式")
                $("th:eq(2)").children().text("联系地址")
                $("th:eq(3)").children().text("email")

                console.log(json.data)
                var list=json.data
                for (let i=0;i<list.length;i++){
                    var sup=list[i]['sup']
                    var phone=list[i]['phone']
                    var address=list[i]['address']
                    var email=list[i]['email']
                    console.log(sup)
                    console.log(phone)
                    console.log(address)
                    console.log(email)
                    $("#list").children().eq(i).children().children().eq(0).text(sup)
                    $("#list").children().eq(i).children().children().eq(1).text(phone)
                    $("#list").children().eq(i).children().children().eq(2).text(address)
                    $("#list").children().eq(i).children().children().eq(3).text(email)
                }
            }
        });
    }



</script>
</body>
</html>